package com.iwat.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.iwat.pojo.User;
import com.iwat.vo.DictVo;
import com.iwat.vo.ListDictVo;
import com.iwat.vo.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author wangweiqiang
 * @Classname UserController
 * @Date 2023/9/22 10:10
 * @Description
 */
@RestController
@AllArgsConstructor
public class UserController {
    private final com.iwat.service.UserService userService;

    @GetMapping("/test")
    public Result test(){
        List<User> users = userService.queryUser();
        DictVo dictVo = new DictVo();
        dictVo.setObj(users.stream().findFirst().orElse(null));
        return Result.ok(dictVo);
    }

    @GetMapping("/testList")
    public Result testList(){
        List<User> users = userService.queryUser();
        ListDictVo listDictVo = new ListDictVo();
        listDictVo.setList(users);
        return Result.ok(listDictVo);
    }

    @GetMapping("/testPage")
    public Result testpage(){
        IPage<User> userPage = userService.queryPage();

        return Result.ok(userPage);
    }


    /**
     * 不使用注解，使用连表查询的方式
     * @return
     */
    @GetMapping("/testListWithJoin")
    public Result testListWithJoin(){
        List<User> users = userService.testListWithJoin();
        return Result.ok(users);
    }
}
